package com.bwie.pojo;

import com.bwie.enums.ResultStatus;
import lombok.Data;

/**
 * @author: 作者
 * @create: 2025-01-08 14:17
 * @Description: TODO
 */
@Data
public class R<T> {

    private Integer code;
    private String msg;
    private T data;

    public R() {
    }

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static R ok() {
        R ok = new R(2000, "成功", null);
        return ok;
    }

    public static R ok(ResultStatus resultStatus) {
        R ok = new R(resultStatus.getCode(), resultStatus.getMsg(), null);
        return ok;
    }

    public static <T> R ok(T data) {
        R ok = new R(2000, "成功", data);
        return ok;
    }

    public static <T> R ok(ResultStatus resultStatus, T data) {
        R ok = new R(resultStatus.getCode(), resultStatus.getMsg(), data);
        return ok;
    }

    public static R err() {
        R ok = new R(4000, "失败", null);
        return ok;
    }

    public static R err(ResultStatus resultStatus) {
        R ok = new R(resultStatus.getCode(), resultStatus.getMsg(), null);
        return ok;
    }

    /**
     * 方法的流式调用
     *
     * @param msg
     * @return set方法  void=====>返回当前对象
     */
    public R msg(String msg) {
        this.msg = msg;
        return this;
    }

    public R data(T data) {
        this.data = data;
        return this;
    }

    public R code(Integer code) {
        this.code = code;
        return this;
    }


}
